package com.vf.admin.miaodong.controller;

import com.vf.admin.client.service.AppPriceSetService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppPriceSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/after/prise")
public class AfterPriceSetController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    AppPriceSetService appPriceSetService;

    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean, Integer type) {
        try {
            Map<String, Object> paramap = new HashMap<>();
            if(type != null) {
                paramap.put("type", type);
            }

            List<AppPriceSet> list = appPriceSetService.page(paramap, splitPageBean);
            request.setAttribute("list", list);
            request.setAttribute("splitPage", splitPageBean);
            return this.sucess("/web/after/prise/list");
        } catch (Exception e) {
            return this.error("系统繁忙");
        }
    }

    @RequestMapping("/save")
    @ResponseBody
    public Result addBanner(AppPriceSet appPriceSet) {
        try {
            appPriceSetService.save(appPriceSet);
            return sucessJSON("success");
        } catch (Exception e) {
            return errorJSON("系统繁忙");
        }
    }

    /**
     * 详情
     */
    @RequestMapping("/detail")
    public String detail(Integer id) {
        try {
            AppPriceSet appBanner = appPriceSetService.info(id);

            request.setAttribute("obj", appBanner);
            return this.sucess("/web/after/prise/edit");
        } catch (Exception e) {
            logger.error("获取轮播图异常", e);
            return this.error("系统繁忙");
        }
    }

    @RequestMapping("/del")
    @ResponseBody
    public Result del(Integer id) {
        try {
            appPriceSetService.del(id);
            return this.sucessJSON("删除成功");
        } catch (Exception e) {
            return this.errorJSON("系统繁忙");
        }
    }

    @RequestMapping("/gotoAdd")
    public String gotoAdd() {
        return this.sucess("/web/after/prise/add");
    }
}
